package bg.rsa_project.gui;

import bg.rsa_project.pi_calculator.PiCalculator;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JTextArea;

/**
 *
 * @author Teofana Gadjeva
 * @author Nikola Pandurski
 */
public class GUI extends javax.swing.JFrame {

    /**
     * Creates new form GUI
     */
    public GUI() {
        initComponents();
        txr_pi_result.setWrapStyleWord(true);
        txr_pi_result.setLineWrap(true);
        this.setResizable(false);
    }

    public JButton getBtn_start() {
        return btn_start;
    }

    public void setBtn_start(JButton btn_start) {
        this.btn_start = btn_start;
    }

    public JButton getBtn_terminate() {
        return btn_terminate;
    }

    public void setBtn_terminate(JButton btn_terminate) {
        this.btn_terminate = btn_terminate;
    }

    public JComboBox getCmb_precision() {
        return cmb_precision;
    }

    public void setCmb_precision(JComboBox cmb_precision) {
        this.cmb_precision = cmb_precision;
    }

    public JComboBox getCmb_threads_count() {
        return cmb_threads_count;
    }

    public void setCmb_threads_count(JComboBox cmb_threads_count) {
        this.cmb_threads_count = cmb_threads_count;
    }

    public JLabel getLbl_exec_time() {
        return lbl_exec_time;
    }

    public void setLbl_exec_time(JLabel lbl_exec_time) {
        this.lbl_exec_time = lbl_exec_time;
    }

    public JTextArea getTxr_pi_result() {
        return txr_pi_result;
    }

    public void setTxr_pi_result(JTextArea txr_pi_result) {
        this.txr_pi_result = txr_pi_result;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fileChooser = new javax.swing.JFileChooser();
        cmb_threads_count = new javax.swing.JComboBox();
        lbl_thread_count = new javax.swing.JLabel();
        lbl_precision = new javax.swing.JLabel();
        cmb_precision = new javax.swing.JComboBox();
        lbl_title = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txr_pi_result = new javax.swing.JTextArea();
        btn_start = new javax.swing.JButton();
        btn_terminate = new javax.swing.JButton();
        lbl_time = new javax.swing.JLabel();
        lbl_exec_time = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        fileItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lbl_thread_count.setText("Threads");
        lbl_thread_count.setToolTipText("");

        lbl_precision.setText("Precision");

        lbl_title.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        lbl_title.setText("Pi Calculator");

        txr_pi_result.setColumns(20);
        txr_pi_result.setRows(5);
        jScrollPane1.setViewportView(txr_pi_result);

        btn_start.setText("Start");

        btn_terminate.setText("Terminate");

        lbl_time.setText("Time");

        lbl_exec_time.setText("0");

        fileMenu.setText("Save to file");

        fileItem.setText("Choose file");
        fileItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileItemActionPerformed(evt);
            }
        });
        fileMenu.add(fileItem);

        jMenuBar1.add(fileMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(lbl_title)
                        .addGap(131, 131, 131))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbl_thread_count)
                        .addGap(18, 18, 18)
                        .addComponent(cmb_threads_count, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lbl_precision)
                        .addGap(18, 18, 18)
                        .addComponent(cmb_precision, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lbl_time)
                        .addGap(18, 18, 18)
                        .addComponent(lbl_exec_time)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btn_start, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btn_terminate, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbl_title)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmb_threads_count, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_thread_count)
                    .addComponent(lbl_precision)
                    .addComponent(cmb_precision, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_terminate)
                    .addComponent(btn_start)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lbl_time)
                        .addComponent(lbl_exec_time)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fileItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileItemActionPerformed
        System.out.println("blasia");
        int returnVal = fileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();
            if (!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException ex) {
                    Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            PiCalculator.setFileOutputPath(file.getAbsolutePath());

        } else {
            System.out.println("File access cancelled by user.");
        }
    }//GEN-LAST:event_fileItemActionPerformed

    public JFileChooser getFileChooser() {
        return fileChooser;
    }

    public void setFileChooser(JFileChooser fileChooser) {
        this.fileChooser = fileChooser;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_start;
    private javax.swing.JButton btn_terminate;
    private javax.swing.JComboBox cmb_precision;
    private javax.swing.JComboBox cmb_threads_count;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JMenuItem fileItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbl_exec_time;
    private javax.swing.JLabel lbl_precision;
    private javax.swing.JLabel lbl_thread_count;
    private javax.swing.JLabel lbl_time;
    private javax.swing.JLabel lbl_title;
    private javax.swing.JTextArea txr_pi_result;
    // End of variables declaration//GEN-END:variables
}
